package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Appointment;
import cn.wolfcode.domain.Business;
import cn.wolfcode.domain.JsonRequest;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.enums.AppointmentStarusEnum;
import cn.wolfcode.service.IAppointmentService;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.ISystemDictionaryItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/fun")
public class IndexController {

    @Autowired
    private ISystemDictionaryItemService iSystemDictionaryItemService;
    @Autowired
    private IBusinessService iBusinessService;
    @Autowired
    private IAppointmentService appointmentService;

    @RequestMapping("/index")
    public String shop(Model model){
        List<SystemDictionaryItem> list=iSystemDictionaryItemService.selectSell();
        model.addAttribute("syis",list);
        boolean b=true;
        Business business=iBusinessService.selectAdmin(b);
        model.addAttribute("business",business);
        List<Business> listbusiness=iBusinessService.listAll();
        model.addAttribute("allbusiness",listbusiness);
        return "index";
    }

    @RequestMapping("/save")
    @ResponseBody
    public JsonRequest save( Appointment appointment) {
//        新增有两种情况,一种是在首页预约,状态是待确认,一种是在客户预约,状态是履行中
        JsonRequest jsonRequest=new JsonRequest();
        appointment.setStatus(AppointmentStarusEnum.PEND.getValue());
        appointmentService.save(appointment);
        return jsonRequest;
    }


}
